package com.jiuzhe.commercial.ui.my;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.constant.Constants;
import com.jiuzhe.commercial.http.CallBack;
import com.jiuzhe.commercial.http.HttpClient;
import com.jiuzhe.commercial.utils.SPUtil;
import com.jiuzhe.commercial.utils.UIUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by huanghao on 2018/5/25.
 */

public class IdeaActivity extends BaseActivity {
    @BindView(R.id.et_idea)
    EditText eIdea;
    @BindView(R.id.tv_submit)
    Button tvSubmit;
    private String etIdea;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_idea);
        setTitle("意见反馈");
    }

    @Override
    protected void loadData() {

    }


    @OnClick({R.id.tv_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_submit:
                submitIdea();
                break;

        }
    }

    private void submitIdea() {
        etIdea = eIdea.getText().toString().trim();
        if (TextUtils.isEmpty(etIdea)){
            UIUtils.showToastSafe("请输入你的想法");
            return;
        }

        HashMap<String, String> map = new HashMap<>();
        String token = SPUtil.getString(this, Constants.TOKEN);
        String id = SPUtil.getString(this, Constants.ID);
        String mer_id = SPUtil.getString(this, Constants.MERCHANTID);
        String autoSignStr = Constants.USERFEEDBACK.substring(Constants.USERFEEDBACK.lastIndexOf("0/") + 1) + "?token=";
        String signStr = UIUtils.Md5(autoSignStr + token);
        map.put("token", id);
        map.put("sign", signStr);
        map.put("id", mer_id);
        map.put("content", etIdea);

        HttpClient.post(this, Constants.USERFEEDBACK, map, new CallBack<String>() {
            @Override
            public void onSuccess(String result) {
               UIUtils.showToastSafe("意见反馈成功");
               finish();
            }
        });
    }}



